#ifndef GY_GRAPHICSVIEW_H
#define GY_GRAPHICSVIEW_H

#include "BasicGraphics/GY_GraphicsCenterItem.h"
#include "BasicGraphics/GY_GraphicsEditItem.h"
#include "BasicGraphics/GY_GraphicsLineItem.h"
#include "BasicGraphics/GY_GraphicsRotTick.h"
#include "BasicGraphics/GY_GraphicsEllipseItem.h"
#include "BasicGraphics/GY_GraphicsLinearTick.h"
#include "BasicGraphics/GY_GraphicsCrown.h"
#include "Graphics/BasicGraphics/GY_GraphicsCircleItem.h"
#include "Graphics/BasicGraphics/GY_GraphicsCornerStyleRect.h"
#include "Graphics/BasicGraphics/GY_GraphicsWideTextItem.h"
#include "Graphics/BasicGraphics/GY_GraphicsPolygon.h"
#include "Graphics/BasicGraphics/GY_GraphicsPolygonRegular.h"
#include "Graphics/BasicGraphics/GY_GraphicsPolyline.h"
#include "Graphics/BasicGraphics/GY_GraphicsArcItem.h"
#include "Graphics/BasicGraphics/GY_GraphicsBezier.h"
#include "Graphics/BasicGraphics/GY_GraphicsFillet.h"
#include "Graphics/BasicGraphics/GY_GraphicsImage.h"
#include "Graphics/BasicGraphics/GY_GraphicsRectWidthHeight.h"
#include "Graphics/ContainerGraphics/GY_GraphicalObject.h"
#include "Graphics/ContainerGraphics/GY_ClippingRegion.h"
#include "Graphics/ContainerGraphics/GY_MutuallyExclusiveGroup.h"
#include "Graphics/ContainerGraphics/GY_SimpleGroup.h"
#include "Graphics/ContainerGraphics/GY_StencilGroup.h"
#include "Graphics/ContainerGraphics/GY_TransformGroup.h"
#include "Graphics/ContainerGraphics/GY_Button.h"
#include "Graphics/ContainerGraphics/GY_KnobFinite.h"
#include "Graphics/ContainerGraphics/GY_ADI.h"
#include "Graphics/ContainerGraphics/GY_BarChartHoriz.h"
#include "Graphics/ContainerGraphics/GY_BarChartVert.h"
#include "Graphics/ContainerGraphics/GY_DialCircular.h"
#include "Graphics/ContainerGraphics/GY_DialFinite.h"
#include "Graphics/ContainerGraphics/GY_TapeCircular.h"
#include "GY_GraphicsScene.h"
#include "GY_ControlLibrary_global.h"
#include <QObject>
#include <QGraphicsView>
#include <QWidget>
#include <QWheelEvent>
#include <QMouseEvent>
#include <QMimeData>
#include <QPixmap>
#include <QDrag>
#include <QLabel>
#include <QGraphicsPathItem>
#include <QGraphicsTextItem>
#include <ItemView_BeiJing/GY_WidgetReflect.h>

/**
 * @brief The GY_GraphicsView class  画板绘制视图
 */
class GY_CONTROLLIBRARY_EXPORT GY_GraphicsView : public QGraphicsView
{
    Q_OBJECT
public:
    explicit GY_GraphicsView(QWidget *parent = nullptr);

    /**
     * @brief addItem 添加图元
     * @param item
     */
    void addItem(QGraphicsItem *item);
    /**
     * @brief setSelectItem 设置选中的项
     * @param list
     */
    void setSelectItem(QList<QGraphicsItem*> &list);

    /**
     * @brief updateCenter 更新编辑点位置
     * @param item
     */
    void updateEditorPoint(QGraphicsItem *item);

    void registerObjectClass(const QString& className);
    /**
     * @brief registerObjectClass 反射基类
     * @param className 类名
     */
    QObject* newInstanceObjectClass(const QByteArray& className,const QString& guid);

    /**
     * @brief setHideRuler 是否隐藏刻度，当为预览模式时可以设置为true
     * @param val
     */
    void setHideRuler(const bool &val = false);

    /**
     * @brief clearItems 清空画布
     */
    void clearItems();

    /**
     * @brief deleteGraphicItem 删除指定图元
     * @param pItem
     */
    void deleteGraphicItem(QGraphicsItem *pItem);

signals:
    /**
     * @brief mousePointF 当前鼠标所在坐标位置
     * @param pointf
     */
    void mousePointF(const QPointF &pointf);
    /**
     * @brief viewScale 当前场景缩放比例
     * @param scale
     */
    void viewScale(const qreal &scale);
    /**
     * @brief selectChange 当前选中项
     * @param list 当前选中项集合
     */
    void selectChange(const QList<QGraphicsItem *> list);
    /**
     * @brief mouseIsPress 鼠标是否点击
     */
    void mouseIsPress();
    /**
     * @brief sendDropEvent 发送触发放置事件
     * @param objectGuid 组件名称
     * @param pixmap 图像
     * @param point 点
     */
    void sendDropEvent(const QVariant &objectGuid, QString &objectName, QVariant &objectType,QString &dropAreaName);
    /**
     * @brief GY_ObjectChange对象修改事件
     * @param pObject 对象指针
     * @param propertyName 修改的属性名称
     */
    void GY_ObjectChangeEvent(GY_Object* pObject,const QString &propertyName);

public slots:
    /**
     * @brief editPointFChange 可编辑点变化事件
     * @param key 可编辑点名称
     * @param p 新的坐标
     */
    void editPointFChange(QGraphicsItem *item,const QString &key,const QPointF &p);
protected:
    //!相对中心点的位置
    QPointF m_CenterAnchor;
    //!当前位置
    QPoint m_PosAnchor;
    //!鼠标状态
    bool m_IsMousePressed = false;
    void mouseMoveEvent(QMouseEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);

    void dragEnterEvent(QDragEnterEvent *event);
    void dragMoveEvent(QDragMoveEvent *event);
    void dropEvent(QDropEvent *event);

    //!缩放比较
    qreal m_Scale = 1.0;
    /**
     * @brief wheelEvent 鼠标滚轮事件
     * @param event
     */
    void wheelEvent(QWheelEvent *event);
    /**
     * @brief resizeEvent  窗口大小改变事件
     * @param event
     */
    void resizeEvent(QResizeEvent *event);
    /**
     * @brief selectItems 当前选中项
     */
    QList<QGraphicsItem *> selectItems;
    /**
     * @brief m_centerItemMap
     */
    QMap<QString,GY_GraphicsCenterItem*> m_centerItemMap;
    QMap<QString,GY_GraphicsEditItem*> m_editItemMap;

private:
    /**
     * @brief m_pScene  场景对象
     */
    GY_GraphicsScene *m_pScene = nullptr;
    /**
     * @brief m_pPathItem x y刻度绘制对象
     */
    QGraphicsPathItem *m_pPathItem = nullptr;
    /**
     * @brief drawRulerLine 绘制刻度
     */
    void drawRulerLine();
    /**
     * @brief m_TextItemList  刻度文本对象集合
     */
    QList<QGraphicsTextItem*> m_TextItemList;
    /**
     * @brief drawCenterPoint  绘制中心点
     */
    void drawEditPoint();

    //!左上角小黑框
    QGraphicsRectItem *m_pLeftTopRect = nullptr;
};

#endif // GY_GRAPHICSVIEW_H
